home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2005 May / CyberMycha 05-2005 (Poland).bin / Immortal / cotndemo.exe / Data1.cab / combinewithshadowmapobjects.1 < prev    next >
Encoding:
Text File  |  2004-11-16  |  2.2 KB  |  63 lines

  1. // vertex shader to combine shadow map texture with model drawing to create shadows
  2. // this shader is used when drawing objects.
  3.  
  4. vs_1_1                // version
  5. dcl_position v0        // position
  6. dcl_normal v3        // normal
  7. // dcl_color v6        // vertex color
  8. dcl_texcoord v7        // texture coordinates
  9.  
  10. def c21,2,-1,-10,0            // for calculating appropriate zbias
  11. def    c22,0.5,0.5,0.5,0.5        // used to go from -1 to 1 to 0 to 1
  12.  
  13. // constants supplied by app:
  14. // c0-c3: MVP matrix
  15. // c4: material diffuse color
  16. // c5: material ambient color
  17. // c6: shadow color (r,g,b,a)
  18. // c7: fogend,1/(fogend-fogstart),zbias,zfactor
  19. // c8-c11:  light MVP matrix
  20. // c12-c15: light MVP matrix * texture adjustment matrix
  21. // c16: global ambient color
  22. // c17: sunlight direction
  23. // c18: sunlight color
  24. // c19: moonlight direction
  25. // c20: moonlight color
  26.  
  27. // calculate position
  28. m4x4 r0, v0, c0        
  29. mov oPos,r0
  30.  
  31. // oFog = (fogend - dist) / (fogend-fogstart)
  32. sub r1.x,c7.x,r0.w    
  33. mul oFog,r1.x,c7.y    
  34.  
  35. mov oT0,v7            // move the texture coordinate to output
  36.  
  37. m4x4 r0,v0, c12        // compute shadow map texture coordinates 
  38. mov oT1,r0
  39.  
  40. dp3 r0,v3,c17        // compute dot product to get intensity
  41. m4x4 r1,v0, c8        // compute position from point of view of light (just want z from this calc for comparison in pixel shader)
  42.  
  43. slt r1.x,r0.x,c21.w            // r1.x = facing light ? 0 : 1
  44. mul r1.x,r1.x,c21.z            // r1.x = - 10 * r1.x 
  45. add r1.x,r1.x,c7.z            // add zbias (if facing light, zbias, else -10 + zbias so that faces not facing light dont get shadows)
  46.  
  47. mad r0,r0,c22,c22    // range from 0 to 1 instead of -1 to 1
  48. mad oT2.x, r1.z,c7.w,r1.x    // t1.z = the z-value we are going to compare with the texture pixel
  49.  
  50. dp3 r2,v3,c19        // moon direction
  51. mad r2,r2,c22,c22    // range from 0 to 1 instead of -1 to 1
  52. mul r2,r2,c20        // multiply by moonlight color
  53. mul r2,r2,c4        // multiply by material color
  54.  
  55. mov r0.a,c5.a        // ambient a was set to 1.0, we don't want light calculation to modify material alpha
  56. mul r1,c4,r0.x        // r1 = material color * lightnormal * direction
  57. mul r1,r1,c18        // multiply by sunlight color
  58.  
  59. add r1.rgb,r1.rgb,r2.rgb        // add moonlight color
  60.  
  61. add r0,c16,r1        // add global ambient color
  62. mov oD0,r0            // pass the resulting color along to the pixel shader
  63.